from typing import Union

import tornado.ioloop
import tornado.web
import tornado.websocket


class MainHandler(tornado.websocket.WebSocketHandler):
    def open(self):
        print('websocket opened')

    def on_message(self, message: Union[str, bytes]):
        self.write('you said:' + message)

    def on_close(self) -> None:
        print('websocket closed')


app = tornado.web.Application([(r'/', MainHandler)])

if __name__ == '__main__':
    app.listen(8880)
    tornado.ioloop.IOLoop.current().start()
